<template>
	<!-- 购物带功能 -->
	<view class="">
		<view class="pdbJr bgcf cart-box">
			<view class="content ">
				<view class="selected-goods df aic">
					<view class="fs26 app-theme df aic box-handle" style="margin-right: 70rpx;" @click="changeCollect">
						<nmr-icon v-if="bMemberCollectFlag==1" name="shoucang" color="#48A147" size="48"></nmr-icon>
						<nmr-icon v-else islinear linearStyle="linear-gradient(90deg, #48A147 0%, #8AE38A 100%)"
							name="shoucang-4" color="#48A147" size="48"></nmr-icon>
						收藏
					</view>
					<view class="fs26 app-theme df aic box-handle pr" style="margin-right:60rpx;">
						<nmr-icon name="kefu-5" color="#48A147" size="48"></nmr-icon>
						客服
						<button class="share-btn" open-type="contact"></button>
					</view>
					<view class="fs26 app-theme df aic box-handle pr" @click="toShopCart" v-if="source != 'theme'">
						<u-badge absolute :offset="[-13,-4]" size="mini" :count="numAll" type="error">
						</u-badge>
						<nmr-icon name="gouwuche" color="#48A147" size="48"></nmr-icon>
						购物车
					</view>
					<view class="df aic jcc" style="margin-left: auto;" v-if="source == 'theme'">
						<u-button hair-line @click="handlesubmit(0)" class="mr20" throttle-time="0" v-if="stock ==0 || !stock"
							:custom-style="{fontSize: '30rpx', color: '#ffffff',width: '400rpx', height: '88rpx',background: '#47A848'}"
							shape='circle' ripple>预约单</u-button>
						<u-button hair-line @click="handlesubmit(1)" class="mr20" throttle-time="0" v-else
							:custom-style="{fontSize: '30rpx', color: '#ffffff',width: '400rpx', height: '88rpx',background: '#47A848'}"
							shape='circle' ripple>立即下单</u-button>
					</view>
					<view class="df aic jcc" style="margin-left: auto;" v-else>
						<u-button hair-line @click="handleAdd" class="mr20" throttle-time="0" :disabled="!end"
							:custom-style="{fontSize: '30rpx', color: '#ffffff',width: '290rpx', height: '88rpx',background: !end?'#666':'#47A848'}"
							shape='circle' ripple>加入购物车</u-button>
					</view>

				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import Decimal from 'decimal.js'
	import {
		getUrl
	} from "@/utils/login.js";
	export default {
		props: {
			end:{
				type:Boolean,
				default:true
			},
			source: {
				type: String,
				default: ''
			},
			stock:{
				type: [Number, String],
				default: 1
			},
			option:{
				type: Object,
				default: () => {}
			},
			carList: {
				type: Array,
				default: () => []
			},
			bMemberCollectFlag: {
				type: [Number, String],
				default: 1
			},
			type: '',
		},
		watch: {
			carList: {
				handler(e) {
					this.numAll = new Decimal(0)
					e.forEach(i => {
						this.numAll =  new Decimal(i.purNum).add(this.numAll)
					})
				},
				immediate: true,
				deep: true
			}
		},

		data() {
			return {
				showCart: false,
				numAll: 0,
				storeInfo: {},
				showNumber: true
			}
		},
		mounted() {
			this.storeInfo = this.SHOPINFO

		},
		methods: {
			toShopCart() {
				uni.switchTab({
					url: '/pages/shopping/index'
				})
			},
			changeCollect() {
				this.$emit('changeCollect')
			},
			handleAdd() {
				this.$emit('add')
			},
			handlesubmit(e) {
				this.$emit('handlesubmit',e)
			},
			handleSubmit() {
				// #ifndef APP-PLUS
				let token = uni.getStorageSync('token'); //凭证
				if (!token) {
					getUrl()
					return
				}
				if (this.storeInfo.openStatus == 1) {
					this.$u.toast('门店已歇业,明天早点来呦')
					return
				}
				if (this.carList.length === 0) {
					this.$u.toast('请添加购物车')
					return
				}

				uni.navigateTo({
					url: '/pages/confirmOrder/index'
				})
				// #endif
				// #ifdef APP-PLUS
				if (this.carList.length === 0) {
					this.$u.toast('请添加购物车')
					return
				}
				uni.navigateTo({
					url: '/pages/confirmOrder/indexApp'
				})
				// #endif
			},
			handleCert() {
				if (this.carList.length == 0) return
				this.showCart = !this.showCart
			},
			valChange(e) {
				this.$emit('change', e)
			},
			clearCar() {
				// this.showCart = false
				this.$emit('clearCar')
			},
		}
	}
</script>


<style lang="scss" scoped>
	.box-handle {
		flex-direction: column;
	}

	$theme-text: #47A848;

	.spec {
		font-size: 24rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
		// margin-top: 15rpx;
	}

	.cert-box {
		.title {
			font-size: 28rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.cert-box-item {
			padding: 20rpx 0;
			width: 100%;
			border-bottom: 2rpx dashed #47A848;

			&:last-child {
				border-bottom-width: 0;
			}

			.title {
				width: 460rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 36rpx;
				// height: 74rpx;
			}

			.price-box {
				>.price {
					color: #EF2929;
					font-size: 30rpx;
					font-family: PingFang SC-Bold, PingFang SC;
				}

				>.unit {}

				>.old-price {
					color: #999999;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					text-decoration: line-through;
				}
			}
		}

		margin: 20rpx 30rpx;

		.cart-type-box-now {
			padding: 20rpx;
			width: 690rpx;
			background: #FFFDF4;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			opacity: 1;
			border: 1rpx solid #47A848;
		}
	}

	.cert-list-box {
		.header {
			padding: 24rpx 30rpx;

			border-bottom: 2rpx solid #E5E5E5;

			.title {
				font-family: PingFang SC-Bold;
				font-weight: bold;
			}

			.desc {
				font-size: 24rpx;

				.num {
					color: #EF2929;
					font-weight: bold;
				}

			}
		}
	}

	.cart-box {
		width: 100%;
		position: fixed;
		z-index: 1203;
		bottom: 0;
		box-shadow: 0rpx 0rpx 4rpx 1rpx rgba(0, 0, 0, 0.16);

		.content {
			margin: 17rpx 30rpx;

			.empty {
				font-size: 26rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
			}

			.selected-goods {
				width: 100%;

				.title {
					color: $theme-text;
				}

				.price-box {
					align-self: flex-end;

					text:nth-child(1) {
						font-size: 26rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
					}

					text:nth-child(2) {
						font-size: 24rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						color: #EF2929;
					}

					text:nth-child(3) {
						font-size: 32rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #EF2929;
					}
				}
			}
		}

	}
</style>